package org.unicom.quartz.test.local;

import org.quartz.*;

import java.util.Date;

@DisallowConcurrentExecution // 禁止并发执行同一个Job 定义（JobDetail定义的）多个实例
@PersistJobDataAfterExecution // 持久化 JobDetail 中的 JobDataMap (对 Trigger中的JobDataMap 无效)
public class MyJob implements Job {

    private String name;

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        /*JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        JobDataMap triggerMap = jobExecutionContext.getTrigger().getJobDataMap();
        JobDataMap mergeMap = jobExecutionContext.getMergedJobDataMap();
        System.out.println("jobDataMap: " + jobDataMap.getString("job"));
        System.out.println("triggerMap: " + triggerMap.getString("trigger"));
        System.out.println("mergeMap: " + mergeMap.getString("trigger"));

        System.out.println("name: " + name);*/

        /*System.out.println("jobDetail:" + System.identityHashCode(jobExecutionContext.getJobDetail()));
        System.out.println("jobDetail:" + System.identityHashCode(jobExecutionContext.getJobInstance()));*/

      /*  System.out.println("execute: " + new Date());
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }*/

        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        jobDataMap.put("count1", jobDataMap.getInt("count1") + 1);
        JobDataMap triggerMap = jobExecutionContext.getTrigger().getJobDataMap();
        triggerMap.put("count", triggerMap.getInt("count") + 1);
        System.out.println("triggerMap count: " + triggerMap.getInt("count"));
        System.out.println("jobDataMap count: " + jobDataMap.getInt("count1"));


    }
}
